﻿<?php
try{
$ws = "http://192.168.20.211:8088/pgis/services/meeting?wsdl";
$client = new SoapClient ( $ws );
$GLOBALS['client'] = $client;
}
catch (Exception $e){
	echo 102;
}

/**
 * 
 * 1.act代表需要的操作：convokeMeeting，发起对讲；endMeeting，结束对讲；getMeetingUserState，对讲状态
 * handUp，挂断单个手机号码； reCall再次呼入某个手机号码；
 * 
 * 2.发起对讲时：传入需要接听警员的手机号码，格式："13783413776,18703879364,13803840932"
 *
 * 3.返回状态：只有发起对讲时，返回对讲是否成功和对讲唯一标识，中间以逗号隔开。其它方法都返回请求是否成功
 * 100请求成功，101IP地址有误，102其他错误。
 * 
 * 4.挂断、再次呼入：需要传入某个警员的手机号码
 * 
 * 5.注意：只有发起对讲不需要传入对讲唯一标识，其它操作都需要传入对讲唯一标识
 */
$GLOBALS['number'] = $number;
//$number = ''; //对讲唯一标识
if (isset ( $_POST ['act'] )) {
	$action = $_POST ['act']; //需要请求的动作
	if (isset ( $_POST ['number'] )) {
		$GLOBALS['number'] = $_POST ['number'];
	}
	if ($action == "convokeMeeting") { //发起对讲,默认状态为双工状态
		$phoneNo = $_POST ['phoneNo']; //传手机号码，多个手机号码中间用逗号隔开
		$resu = convokeMeeting ( $phoneNo );
		echo $resu . "," . $GLOBALS['number'];
	} else if ($action == "endMeeting") { //结束对讲
		echo endMeeting ();
	} else if ($action == "getMeetingUserState") { //获取对讲状态
		echo getMeetingUserState ();
	} else if ($action == "handUp") { //挂断某个警员
		$phone = $_POST ['phoneNo'];
		echo handUp ( $phone );
	} else if ($action == "reCall") { //再次呼入某个警员
		$phone = $_POST ['phoneNo'];
		echo reCall ( $phone );
	} else if ($action == "setAllDuplexTalk") { //设置全体对讲人员为单工模式
		echo setAllDuplexTalk ();
	} else if ($action == "setDuplexTalk") { //设置某个对讲人员为双工模式
		$phone = $_POST ['phoneNo'];
		echo setDuplexTalk ( $phone );
	} else if ($action == "setAllSimplexTalk") { //设置全体对讲人员为单工模式
		echo setAllSimplexTalk ();
	} else if ($action == "setSimplexTalk") { //设置某个对讲人员为单工模式
		$phone = $_POST ['phoneNo'];
		echo setSimplexTalk ( $phone );
	}
}
//发起对讲,默认状态为双工状态
function convokeMeeting($phoneNo) {
	$resu = $GLOBALS['client']->convokeMeeting ( '110', '13460449303', $phoneNo );
	$resu = explode ( "||", $resu );
	if ($resu [0] == 100) {
		$GLOBALS['number'] = $resu [1];
		return $resu [0];
	} else {
		return $resu [0];
	}
}
//结束对讲
function endMeeting() {
	$resu = $GLOBALS['client']->endMeeting ( $GLOBALS['number'] );
	$resu = explode ( "||", $resu );
	if ($resu [0] == 100) {
		$GLOBALS['number'] = $resu [1];
		return $resu [0];
	} else {
		return $resu [0];
	}
}
//获取对讲状态
function getMeetingUserState() {
	$resu = $GLOBALS['client']->getMeetingUserState ( $GLOBALS['number'] );
	if ($resu [0] == 100) {
		$GLOBALS['number'] = $resu [1];
		return $resu [0];
	} else {
		return $resu [0];
	}
}
//再次呼叫
function reCall($phone) {
	$resu = $GLOBALS['client']->call ( $GLOBALS['number'], $phone );
	if ($resu [0] == 100) {
		$GLOBALS['number'] = $resu [1];
		return $resu [0];
	} else {
		return $resu [0];
	}
}
//挂断某个警员
function handUp($phone) {
	$resu = $GLOBALS['client']->handup ( $GLOBALS['number'], $phone );
	if ($resu [0] == 100) {
		$GLOBALS['number'] = $resu [1];
		return $resu [0];
	} else {
		return $resu [0];
	}
}
//设置全体对讲人员为双工模式
function setAllDuplexTalk() {
	$resu = $GLOBALS['client']->setAllDuplexTalk ( $GLOBALS['number'] );
	if ($resu [0] == 100) {
		$GLOBALS['number'] = $resu [1];
		return $resu [0];
	} else {
		return $resu [0];
	}
}
//设置某个对讲人员为双工模式
function setDuplexTalk($phone) {
	$resu = $GLOBALS['client']->setDuplexTalk ( $GLOBALS['number'], $phone );
	if ($resu [0] == 100) {
		$GLOBALS['number'] = $resu [1];
		return $resu [0];
	} else {
		return $resu [0];
	}
}
//设置全体对讲人员为单工模式
function setAllSimplexTalk() {
	$resu = $GLOBALS['client']->setAllSimplexTalk ( $GLOBALS['number'] );
	if ($resu [0] == 100) {
		$GLOBALS['number'] = $resu [1];
		return $resu [0];
	} else {
		return $resu [0];
	}
}
//设置某个对讲人员为单工模式
function setSimplexTalk($phone) {
	$resu = $GLOBALS['client']->setSimplexTalk ( $GLOBALS['number'], $phone );
	if ($resu [0] == 100) {
		$GLOBALS['number'] = $resu [1];
		return $resu [0];
	} else {
		return $resu [0];
	}
}

?>